package com.spvs.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spvs.common.log.annotation.Log;
import com.spvs.common.log.enums.BusinessType;
import com.spvs.common.security.annotation.RequiresPermissions;
import com.spvs.system.domain.FileArchive;
import com.spvs.system.service.IFileArchiveService;
import com.spvs.common.core.web.controller.BaseController;
import com.spvs.common.core.web.domain.AjaxResult;
import com.spvs.common.core.utils.poi.ExcelUtil;
import com.spvs.common.core.web.page.TableDataInfo;

/**
 * 文件归档Controller
 *
 * @author supervision
 * @date 2024-12-12
 */
@RestController
@RequestMapping("/archive")
public class FileArchiveController extends BaseController
{
    @Autowired
    private IFileArchiveService fileArchiveService;

    /**
     * 查询文件归档列表
     */
    @RequiresPermissions("system:archive:list")
    @GetMapping("/list")
    public TableDataInfo list(FileArchive fileArchive)
    {
        startPage();
        List<FileArchive> list = fileArchiveService.selectFileArchiveList(fileArchive);
        return getDataTable(list);
    }

    /**
     * 导出文件归档列表
     */
    @RequiresPermissions("system:archive:export")
    @Log(title = "文件归档", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FileArchive fileArchive)
    {
        List<FileArchive> list = fileArchiveService.selectFileArchiveList(fileArchive);
        ExcelUtil<FileArchive> util = new ExcelUtil<FileArchive>(FileArchive.class);
        util.exportExcel(response, list, "文件归档数据");
    }

    /**
     * 获取文件归档详细信息
     */
    @RequiresPermissions("system:archive:query")
    @GetMapping(value = "/{archiveId}")
    public AjaxResult getInfo(@PathVariable("archiveId") Long archiveId)
    {
        return success(fileArchiveService.selectFileArchiveByArchiveId(archiveId));
    }

    /**
     * 新增文件归档
     */
    @RequiresPermissions("system:archive:add")
    @Log(title = "文件归档", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FileArchive fileArchive)
    {
        return toAjax(fileArchiveService.insertFileArchive(fileArchive));
    }

    /**
     * 修改文件归档
     */
    @RequiresPermissions("system:archive:edit")
    @Log(title = "文件归档", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FileArchive fileArchive)
    {
        return toAjax(fileArchiveService.updateFileArchive(fileArchive));
    }

    /**
     * 删除文件归档
     */
    @RequiresPermissions("system:archive:remove")
    @Log(title = "文件归档", businessType = BusinessType.DELETE)
	@DeleteMapping("/{archiveIds}")
    public AjaxResult remove(@PathVariable Long[] archiveIds)
    {
        return toAjax(fileArchiveService.deleteFileArchiveByArchiveIds(archiveIds));
    }
}
